<div id="artist-list">
  <h3>artists in this playlist:</h3>
  <ul>
<% (hash=@iTunes.artists(@playlist)).keys.sort_by {|x| x.downcase}.each  do |key| %>
  <li><%= link_to key, url_for(:artist => key) %> <%= hash[key] %></li>
<% end %>
  </ul>
</div>

<div id="library-list">
  <p>
  <%= link_to_function "instructions", "jQuery('#instructions').toggle()"  %>
  </p>
  <div id="instructions" style="display:none;padding: 0.5em">
    <p>Click "que" to add to the end of queue. If a song you try to queue doesn't appear in the queue, it may not be locatable by iTunes (e.g. on a hard drive that isn't connected to your computer.)</p>

    <p>iTunesRails creates an "itunes-rails" playlist to hold the tracks that you queue. Be warned that iTunesRails uses the "comment" field of an iTunes track's metadata to remember who last queued a particular track. So if you have written anything important there, don't queue those tracks with iTunesRails. </p>
  </div>

<div id="playlist-nav-controls">
<% form_tag(source_playlists_path(:source_id => 0), :method => :get, :id => "playlist-switcher") do %>
  <%= select_tag "playlist_index", @iTunes.playlists.enum_with_index.collect { |p,i| 
    if p.name == @playlist.name 
      "<option value='#{i}' selected='selected'>#{p.name}</option>"
    else
      "<option value='#{i}' >#{p.name}</option>"
    end
  } %>
  <%= submit_tag "go to playlist" %>
<% end %>
<form action="<%= url_for() %>" method="get">
  <input type="text" name="q" value="<%= params[:q]  %>"/>
  <input type="submit" value="search"/>
</form>
</div>

<br/>
<h3 class="playlist-title">playlist:</h3>
<h1 class="playlist-title"><%= @playlist.name %></h1>
<%=link_to "up", "/" %> :
<%=link_to "clear ordering or search" %>

<%= render :partial => 'paginator' %>

<% if params[:artist] %>
  <h3>All Tracks in this Playlist by <%= params[:artist] %></h3>
<% end %>
<% form_remote_tag(:url => url_for(:controller => "tracks", :action => "queue", :id => "multiple"), :method => :put, :loading => "$('queue-changing').show()", :complete => "$('queue-changing').hide(); jQuery('.track-checkbox').attr('checked', false);" ) do  %>
  <%= button_to_function "select all tracks", "jQuery('.track-checkbox').attr('checked', true);"  %>
  <%= submit_tag "queue all selected" %>
  <%= button_to_function "clear selections", "jQuery('.track-checkbox').attr('checked', false);"  %>
<table style="margin-top: 1em">
  <colgroup>
    <col id="c0"/>
    <col id="c0b"/>
    <col id="c1"/>
    <col id="c2"/>
    <col id="c3"/>
  </colgroup>
  <thead style="text-align:left">
    <th></th>
    <th></th>
    <th><%= link_to_unless params[:order] == "artist" || params.has_key?(:q), "artist", :order => "artist" %></th>
    <th><%= link_to_unless params[:order] == "name" || params.has_key?(:q), "track", :order => "name", :q => params[:q] %></th>
    <th><%= link_to_unless params[:order] == "album" || params.has_key?(:q), "album", :order => "album", :q => params[:q] %></th>
  </thead>
<% @tracks.each do |track| %>
  <tr class="<%= cycle('odd', 'even') %>">
    <td>
      <%= check_box_tag "tracks[]", track.databaseID, nil, {:class => "track-checkbox"} %>
    </td>
    <td>
      <%= link_to_remote 'que', :url => queue_track_path(:id => track.databaseID, :q => params[:q], :order => params[:order]), :method => :put,
        :loading => "$('progress').show()", :complete => "$('progress').hide()" %>
    </td>
    <td><%= track.artist %></td>
    <td>
      <%= track.name %>
    </td>
    <td><%= track.album %></td>
  </tr>
<% end %>
</table>
<% end %> <!-- end of form -->

<%= render :partial => 'paginator' %>
</div>
